#ifndef __RSA_H__
#define __RSA_H__
// https://github.com/andrewkiluk/RSA-Library

#include "header.h"
#include "longlong.h"
// typedef unsigned long myuint64_t;

typedef struct public_key_class
{
    myuint64_t modulus;
    myuint64_t exponent;
} private_key_class;

/**
 * @brief This function generates public and private keys, then stores them in
 * the structures you provide pointers to. The 3rd argument should be the text
 * PRIME_SOURCE_FILE to have it use the location specified above in this header.
 * @param [out] pub 公钥
 * @param [out] priv 私钥
 */
void rsa_gen_keys( struct public_key_class *pub, private_key_class *priv );
/**
 * This function will encrypt the data pointed to by message. It returns a
 * pointer to a heap array containing the encrypted data, or NULL upon failure.
 * This pointer should be freed when you are finished. The encrypted data will
 * be 8 times as large as the original data.
 * @param [in]  message 需要被加密的明文
 * @param [in] message_size 明文长度,以字节为单位
 * @param [in] pub 用于加密的公开密钥
 * @param [out] encrypted 密文
 */
bool rsa_encrypt( const uint8_t *message, const size_t message_size,
                        const struct public_key_class *pub,
                        myuint64_t *encrypted );
 /**
 * @brief This function will decrypt the data pointed to by message. It returns a
 * pointer to a heap array containing the decrypted data, or NULL upon failure.
 * This pointer should be freed when you are finished. The variable message_size
 * is the size in bytes of the encrypted message. The decrypted data will be
 * 1/8th the size of the encrypted data.
 * @param [in] message 密文
 * @param [in] message_size 密文长度，以字节为单位
 * @param [in] priv 私钥
 * @param [out] decrypted 解密后的数据
 */
bool rsa_decrypt( const myuint64_t *message, const size_t message_size,
                   const private_key_class *priv, uint8_t *decrypted );

#endif
